package org.liaohailong.library.util

import android.content.Context
import java.io.Closeable
import java.io.InputStream
import java.lang.Exception

/**
 * Author: liaohailong
 * Date: 2019/4/27
 * Time: 10:43
 * Description: 公共方法
 **/
object Utility {

    fun getAssestFileAsString(context: Context, fileName: String): String? {
        var inputStream: InputStream? = null
        return try {
            inputStream = context.assets.open(fileName)
            val bytes = ByteArray(inputStream.available())
            inputStream.read(bytes)
            String(bytes)
        } catch (e: Exception) {
            null
        } finally {
            closeIO(inputStream)
        }
    }

    fun closeIO(closeable: Closeable?) {
        try {
            closeable?.close()
        } catch (e: Exception) {
            e.printStackTrace()
        }
    }
}